<?php

require_once("inc/dbConnection.php");

class accounts {

	private static $instance;

	// private constructor
	private function __construct() {}
    
	public static function getInstance() {
    
		if(!isset(self::$instance)) {
			$object= __CLASS__;
			self::$instance = new $object;
		}

		return self::$instance;
	}
    
    // get mysql result set type as set of all accounts
    function get_accounts() {
    
        $db = new Dbo();
        
        $sql = "SELECT `account_id`, `lastname`, `firstname`, `email`, `permission` FROM accounts";
        
        $result = $db->runQuery($sql);
        
        return $result;

    }
    
    // add an account to the existing db
    function add_account($firstname, $lastname, $password, $permission, $email) {
    
        $db = new Dbo();
        
        $sql = "INSERT INTO accounts " .
            "(`password`, `permission`, `firstname`, `lastname`, `email`) " . 
            "VALUES " . 
            "('{$password}', '{$permission}', '{$firstname}', '{$lastname}', '{$email}')";
            
        $result = $db->runQuery($sql);
        
    }
    
    
    function delete_account($account_id) {
    
        $db = new Dbo();
        
        $sql = "DELETE FROM accounts WHERE account_id = " . $account_id;
        $result = $db->runQuery($sql);
        
    }
    

    
}

?>